package netty.inoutbandhandler;

import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.nio.charset.Charset;

/**
 * Created by IntelliJ
 * Author:熊磊
 */
public class MyClientHandler extends SimpleChannelInboundHandler<Long> {
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        System.out.println("MyClientHandler 发送数据");
        ctx.writeAndFlush(123456L);
        //如果发送的不是long 类型 那么 在Encoder 源码中不会进行编码 , 而是直接write 出去
        //ctx.writeAndFlush(Unpooled.copiedBuffer("abcdabcdabcdabcd", Charset.defaultCharset()));
    }

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Long msg) throws Exception {
        System.out.println("接收到服务器端返回的消息 " +msg);
    }
}
